package com.example.index.ui

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.example.index.R
import kotlinx.android.synthetic.main.activity_daily_task.*
import kotlinx.android.synthetic.main.item_daily_task_layout.view.*
import me.drakeet.multitype.ItemViewBinder
import me.drakeet.multitype.MultiTypeAdapter

class DailyTaskActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_daily_task)


        val typeAdapter = MultiTypeAdapter()

        typeAdapter.register(object : ItemViewBinder<DailyTask, ViewHolder>() {
            override fun onBindViewHolder(holder: ViewHolder, item: DailyTask) {

//                (holder.itemView as CardView).setCardBackgroundColor(item.name)
                holder.itemView.app_name.text = item.name
            }

            override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): ViewHolder {

                return ViewHolder(inflater.inflate(R.layout.item_daily_task_layout, parent, false))
            }

        })

        val datas = arrayListOf(
            DailyTask("捉妖记"),
            DailyTask("哪吒闹海"),
            DailyTask("大圣"),
            DailyTask("恶人转"),
            DailyTask("寄生虫"),
            DailyTask("恶人转1"),
            DailyTask("恶人2")
        )
        typeAdapter.items = datas
        taskRv.layoutManager = SheetLayoutManager()
        taskRv.adapter = typeAdapter
//        val itemTouchHelper = ItemTouchHelper(TaskDragCallback(taskRv, typeAdapter, datas))
//        itemTouchHelper.attachToRecyclerView(taskRv)
    }

    class DailyTask(var name: String)


    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {


    }

}
